package dao;

import Mysqlcon.Conn;
import pojo.users.User;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Logindao extends Conn {
	public User logingetinfo(String username,String password) throws Exception{

		String org = null;
		String tel = null;
		String email = null;

		boolean flge=false;
		String sql="select * from user where username=?";
		PreparedStatement ps = null;

		ps = connection.prepareStatement(sql);

		ps.setString(1, username);

       User user2= new User("NULL","123","1",tel,email);
		try {
			ResultSet res = ps.executeQuery();
			while (res.next()){

				if(password.equals(res.getString("userpassword"))){

					org=res.getString("org");
					tel=res.getString("tel");
					email=res.getString("email");
					flge=true;
					user2=new User(username,password,org,tel,email);
					break;
				}


			}
			if (!flge){
				System.out.println("登录失败！账号或密码错误");
			}else{
				System.out.println("登录成功！");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}


		return user2;
	}

}
